package com.xw.comm.service;

import gnu.io.NoSuchPortException;
import gnu.io.PortInUseException;
import gnu.io.SerialPort;
import gnu.io.UnsupportedCommOperationException;

import java.util.TooManyListenersException;

/**
 * 串口类
 * @author xiongwei_vendor
 * @date 2020/12/8 19:25
 */
public interface SerialPortService {


    /**
     * 串口启动
     * @param com 串口号
     * @throws NoSuchPortException 异常
     * @throws PortInUseException 异常
     * @throws UnsupportedCommOperationException 异常
     * @throws TooManyListenersException 异常
     */
    void start(String com) throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException, TooManyListenersException;

    /**
     * 串口停止
     * @param com 串口号
     */
    void stop(String com);

    /**
     * 发送数据
     * @param data 数据
     * @return 发送是否成功
     */
    boolean sendMessage(byte[] data);

    /**
     * 获取SerialPort对象
     * @return SerialPort
     */
    SerialPort getSerialPort();

}
